﻿@using OBUCare.Core.Models;
@using OBUCare.Web.Infrastructure;
@using OBUCare.Core.Common;
@using OBUCare.Web.Models;
@using OBUCare.Core.DataAccess;
@model UserReceiveObuInfo
@{
    string spareObuNo = @Model.RepairOrder.SPARE_OBU_NO == ""
        || @Model.RepairOrder.SPARE_OBU_NO == null ? "无备签" : @Model.RepairOrder.SPARE_OBU_NO;
    string spareObuNoPrice = @Model.RepairOrder.SPARE_OBU_PRICE == 0
        || @Model.RepairOrder.SPARE_OBU_PRICE == null ? "0" : @Model.RepairOrder.SPARE_OBU_PRICE.ToString();
    decimal repairFeeSum = 0;
    decimal serviceFeeSum = 0;
    decimal allAmount = 0;
    decimal serviceFee = 0;
    int infocustomerDate = 0;
}
<div style="text-align: center">
    <table width="800px">
        <tr>
            <td align="center" colspan="4">
                <span style="font-size: 14px; font-weight: bold">基本信息</span>
            </td>
        </tr>
        <tr>
            <td style="width: 200px; text-align: right">厂家：
            </td>
            <td style="width: 200px; text-align: left">
                @Html.DisplayFor(m => m.RepairOrder.SUPPLIER)
            </td>
            <td style="width: 200px; text-align: right">标签型号：
            </td>
            <td style="width: 200px; text-align: left">
                @Html.DisplayFor(m => m.RepairOrder.SPEC_NAME)
            </td>
        </tr>
        <tr>
            <td style="text-align: right">标签号：
                @Html.Hidden("OBU_NO", Model.RepairOrder.OBU_NO, new { width = "0px" })
            </td>
            <td style="text-align: left">
                @Html.DisplayFor(m => m.RepairOrder.OBU_NO)
            </td>
            <td style="text-align: right">所有人：
            </td>
            <td style="text-align: left">
                @Html.DisplayFor(m => m.RepairOrder.USER_NAME)
            </td>
        </tr>
        <tr>
            <td style="text-align: right">车牌号：
            </td>
            <td style="text-align: left">
                @Html.DisplayFor(m => m.RepairOrder.VEHICLE_PLATE_NO)
            </td>
            <td style="text-align: right">车型：
            </td>
            <td style="text-align: left">
                @Html.DisplayFor(m => m.RepairOrder.VEHICLE_CLASS_NAME)
            </td>
        </tr>
        <tr>
            <td style="text-align: right">客户编号：
                @Html.Hidden("USER_NO", Model.RepairOrder.USER_NO, new { width = "0px" })
            </td>
            <td style="text-align: left">
                @Html.DisplayFor(m => m.RepairOrder.USER_NO)
            </td>
            <td style="text-align: right">发行日期：
                @Html.Hidden("REGISTER_DATE", Model.RepairOrder.REGISTER_DATE, new { width = "0px" })
            </td>
            <td style="text-align: left">
                @Html.DisplayFor(m => m.RepairOrder.REGISTER_DATE)
            </td>
        </tr>
    </table>
    <table width="800px">
        <tr>
            <td style="width: 200px; text-align: right">受理营业厅：
                @Html.Hidden("RepairOrderID", Model.RepairOrder.ID)
            </td>
            <td style="width: 200px; text-align: left">
                @Html.DisplayFor(m => m.RepairOrder.AGENT_NAME)
            </td>
            <td style="width: 200px; text-align: right">受理日期：
                @Html.Hidden("Order_id", Model.RepairOrder.ID, new { width = "0px" })
            </td>
            <td style="width: 200px; text-align: left">
                @Html.DisplayFor(m => m.RepairOrder.CREATED_DATE)
            </td>
        </tr>
        <tr>
            <td style="width: 200px; text-align: right">送修人：
            </td>
            <td style="width: 200px; text-align: left">
                @Html.DisplayFor(m => m.RepairOrder.REPORTER)
            </td>
            <td style="width: 200px; text-align: right">固定电话：
            </td>
            <td style="width: 200px; text-align: left">
                @Html.DisplayFor(m => m.RepairOrder.TEL_NO)
            </td>
        </tr>
        <tr>
            <td style="width: 200px; text-align: right">手机号：
            </td>
            <td style="width: 200px; text-align: left">
                @Html.DisplayFor(m => m.RepairOrder.MOBILE_TEL_NO)
            </td>
            <td style="width: 200px; text-align: right">维修性质：
            </td>
            <td style="width: 200px; text-align: left">
                @Html.DisplayFor(m => m.RepairType.TITLE)
            </td>
        </tr>
        <tr>
            <td style="width: 200px; text-align: right">备签号：
            </td>
            <td style="width: 200px; text-align: left">
                @spareObuNo
            </td>
            <td style="width: 200px; text-align: right">押金：
            </td>
            <td style="width: 200px; text-align: left">
                @spareObuNoPrice
            </td>
        </tr>
        <tr>
            <td style="width: 200px; text-align: right">客户是否维修：
            </td>
            <td style="width: 200px; text-align: left">
                @Html.DisplayFor(m => m.RepairOrder.CONFIRM_REPAIRED_Title)
            </td>
            <td style="width: 200px; text-align: right">通知领取时间：
            </td>
            <td style="width: 200px; text-align: left">
                @Html.DisplayFor(m => m.RepairOrder.MODIFY_DATE)
            </td>
        </tr>
        <tr>
            <td colspan="4" align="center">
                <span style="font-size: 14px; font-weight: bold">维修费</span>
            </td>
        </tr>
        @if (Model != null)
        {
            if (Model.RepairFeeModel.Count() > 0)
            {
                foreach (var item in Model.RepairFeeModel)
                {
                    repairFeeSum = repairFeeSum + item.RepairPrice.PRICE;
            <tr>
                <td style="width: 200px; text-align: right">故障点：
                </td>
                <td style="width: 200px; text-align: left">@item.PartsType.PARTS_NAME
                </td>
                <td style="width: 200px; text-align: right">金额：
                </td>
                <td style="width: 200px; text-align: left">@item.RepairPrice.PRICE<span>(元) </span>
                </td>
            </tr>
                }
            }
            else
            {
            <tr>
                <td style="width: 200px; text-align: right">故障点：
                </td>
                <td style="width: 200px; text-align: left">无
                </td>
                <td style="width: 200px; text-align: right">金额：
                </td>
                <td style="width: 200px; text-align: left">0(元)
                </td>
            </tr>
            }
        }
        else
        {
            <tr>
                <td style="width: 200px; text-align: right">故障点：
                </td>
                <td style="width: 200px; text-align: left">无
                </td>
                <td style="width: 200px; text-align: right">金额：
                </td>
                <td style="width: 200px; text-align: left">0(元)
                </td>
            </tr>
        }
        @if (Model != null)
        {
            if (Model.RepairFeeAdjust.Count() > 0)
            {
                foreach (var item in Model.RepairFeeAdjust)
                {
                    repairFeeSum = repairFeeSum + item.AMOUNT;
            <tr>
                <td style="width: 200px; text-align: right">调整费用：
                </td>
                <td style="width: 200px; text-align: left">@item.AMOUNT<span>（元）</span>
                </td>
                <td style="width: 200px; text-align: right">调整原因：
                </td>
                <td style="width: 200px; text-align: left">@item.COMMENT
                </td>
            </tr>
                }
            }
            else
            {
            <tr>
                <td style="width: 200px; text-align: right">调整费用：
                </td>
                <td style="width: 200px; text-align: left">0（元）
                </td>
                <td style="width: 200px; text-align: right">调整原因：
                </td>
                <td style="width: 200px; text-align: left">无
                </td>
            </tr>
            }
        }
        else
        {
            <tr>
                <td style="width: 200px; text-align: right">调整费用：
                </td>
                <td style="width: 200px; text-align: left">0（元）
                </td>
                <td style="width: 200px; text-align: right">调整原因：
                </td>
                <td style="width: 200px; text-align: left">无
                </td>
            </tr>
        }
        <tr>
            <td colspan="2"></td>
            <td style="width: 200px; text-align: right">
                <span style="font-size: 13px; font-weight: bold">维修费合计:</span>
                @Html.Hidden("repairFeeSum", repairFeeSum)
            </td>
            <td style="width: 200px; text-align: left">
                <span style="font-size: 13px; font-weight: bold">@repairFeeSum.ToString() (元)</span>
            </td>
        </tr>
        <tr>
            <td colspan="4" align="center">
                <span style="font-size: 14px; font-weight: bold">服务费</span>
            </td>
        </tr>
        @if (Model != null)
        {

            //serviceFeeSum = serviceFeeSum ;
            <tr>
                <td style="width: 200px; text-align: right">逾期天数：
                </td>
                <td style="width: 200px; text-align: left">
                    @{ if (Model.RepairOrder.SPARE_OBU_ISSUE_DATE == null && Model.RepairOrder.SPARE_OBU_NO == null &&
                           Model.RepairOrder.SPARE_OBU_PRICE == null) //如果没备签 则不计算服务费
                       {
                           infocustomerDate = 0;
                       }
                       else
                       {
                           REPAIR_ORDER_TRACKING o = (from i in new OBU_CAREContext().REPAIR_ORDER_TRACKING.ToList()
                                                      where i.REPAIR_ORDER_ID == Model.RepairOrder.ID &&
                                                      i.REPAIR_ORDER_Status == Convert.ToInt32(RepairOrderStatus.InformedCustomer)
                                                      select i)
                                                    .FirstOrDefault();
                           infocustomerDate = o == null || o.CREATED_DATE == null ? 0 :
                               (DateTime.Now - Model.RepairOrder.MODIFY_DATE.AddDays(Convert.ToInt32(ServiceFeeCheck.ServiceFeeDay))).Days < 0 ? 0 :
                               (DateTime.Now - Model.RepairOrder.MODIFY_DATE.AddDays(Convert.ToInt32(ServiceFeeCheck.ServiceFeeDay))).Days;
                       }
                    }
                    @infocustomerDate<span>(天)</span>
                </td>
                <td style="width: 200px; text-align: right">服务费单价：
                </td>
                <td style="width: 200px; text-align: left">@ServiceFeeCheck.ServiceFeePrice.ToInt()<span>(元)/天</span>
                </td>
            </tr>
            <tr>
                <td colspan="2"></td>
                <td style="width: 200px; text-align: right">服务费共计：
                </td>
                <td style="width: 200px; text-align: left">
                    @*@{serviceFee = Convert.ToInt32(infocustomerDate * ServiceFeeCheck.ServiceFeePrice.ToInt());
                      serviceFeeSum = serviceFee;}
                    @serviceFee <span>(元)</span>*@
                    @if (Model.RepairOrder.SPARE_OBU_NO != null || Model.RepairOrder.SPARE_OBU_PRICE != null || Model.RepairOrder.SPARE_OBU_ISSUE_DATE != null)
                    {
                        serviceFee = Convert.ToInt32(infocustomerDate * ServiceFeeCheck.ServiceFeePrice.ToInt());
                        serviceFeeSum = serviceFee > 300 ? 300 : serviceFee;
                    }
                    else
                    {
                        serviceFee = 0;
                        serviceFeeSum = serviceFee;
                    }
                    @(serviceFee > 300 ? 300 : serviceFee) <span>(元)</span>
                </td>
            </tr>
        
        }
        else
        {
            <tr>
                <td style="width: 200px; text-align: right">服务费：
                </td>
                <td style="width: 200px; text-align: left">0（元）
                </td>
                <td style="width: 200px; text-align: right">备注：
                </td>
                <td style="width: 200px; text-align: left">无
                </td>
            </tr>
        }
        @if (Model != null)
        {
            if (Model.ServiceFeeAdjust.Count() > 0)
            {
                foreach (var item in Model.ServiceFeeAdjust)
                {
                    serviceFeeSum = serviceFeeSum + item.AMOUNT;
            <tr>
                <td style="width: 200px; text-align: right">调整费用：
                </td>
                <td style="width: 200px; text-align: left">@item.AMOUNT<span>（元）</span>
                </td>
                <td style="width: 200px; text-align: right">调整原因：
                </td>
                <td style="width: 200px; text-align: left">@item.COMMENT
                </td>
            </tr>
                }
            }
            else
            {
            <tr>
                <td style="width: 200px; text-align: right">调整费用：
                </td>
                <td style="width: 200px; text-align: left">0（元）
                </td>
                <td style="width: 200px; text-align: right">调整原因：
                </td>
                <td style="width: 200px; text-align: left">无
                </td>
            </tr>
            }
        }
        else
        {
            <tr>
                <td style="width: 200px; text-align: right">调整费用：
                </td>
                <td style="width: 200px; text-align: left">0（元）
                </td>
                <td style="width: 200px; text-align: right">调整原因：
                </td>
                <td style="width: 200px; text-align: left">无
                </td>
            </tr>
        }
        <tr>
            <td colspan="2"></td>
            <td style="width: 200px; text-align: right">
                <span style="font-size: 13px; font-weight: bold">服务费合计:</span>
                @Html.Hidden("serviceFeeSum", serviceFeeSum)
                @Html.Hidden("serviceFee", serviceFee)
                @Html.Hidden("infocustomerDate", infocustomerDate)
            </td>
            <td style="width: 200px; text-align: left">
                <span style="font-size: 13px; font-weight: bold">@serviceFeeSum.ToString() (元)</span>
            </td>
        </tr>
        @if (Model != null)
        {
            if (Model.RepairOrder.SPARE_OBU_PRICE > 0)
            {
            <tr>
                <td style="width: 200px; text-align: right">是否完整归还备用标签：
                </td>
                <td style="width: 200px; text-align: left">
                    @Html.DropDownList("returnSpareObu", new List<SelectListItem>
{
    (new SelectListItem() {Text = "是", Value = "true", Selected = true}),
    (new SelectListItem() {Text = "否", Value = "false"})
}, new { style = "width:100px" })
                </td>
                <td style="width: 200px; text-align: right">备注：
                </td>
                <td style="width: 200px; text-align: left">
                    @Html.TextBox("obu_remark", "", new { @style = "width:150px" })
                </td>
            </tr>
            }
        }
        <tr>
            <td style="width: 200px; text-align: right">
                <span style="font-size: 13px; font-weight: bold">收款共计：</span>
                @Html.Hidden("allSum", allAmount)
            </td>
            <td style="width: 200px; text-align: left">
                @if (Model.RepairOrder.CONFIRM_REPAIRED == ConfirmRepairedStatus.Repair.ToInt())
                {
                    allAmount = repairFeeSum + serviceFeeSum;
                }
                else
                {
                    allAmount = 0;
                }
                <span style="font-size: 13px; font-weight: bold">@allAmount (元)</span>
            </td>
            <td style="width: 200px; text-align: right">
                <span style="font-size: 13px; font-weight: bold">退款共计：</span>
            </td>
            <td style="width: 200px; text-align: left">
                <span style="font-size: 13px; font-weight: bold">@spareObuNoPrice (元)</span>
            </td>
        </tr>
        <tr>
            <td colspan="2"></td>
            <td align="center" colspan="2">
                <input type="button" value="确 定" id="btnSubmit" />
                &nbsp; &nbsp; &nbsp;
                <input type="button" value="取 消" id="btnCancel" onclick="clearAll()" />
            </td>
        </tr>
    </table>
    <script src="../../Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $('#btnSubmit').click(function (e) {
                //debugger;
                var value = $('#returnSpareObu').val();
                var checkRemark = $('#obu_remark').val()
                value = $.trim(value);
                if (value == 'false') {
                    if (checkRemark.StringIsNullOrEmpty()) {
                        alert("请输入备注信息");
                        return false;
                    }
                    else {
                        $('#form_id').submit();
                        return true;
                    }
                }
                else {
                    $('#form_id').submit();
                    return true;
                }
            });
        });

        function clearAll() {
            document.getElementById("tbForm").reset();
            $('#divObuContainer').hide();
        }
    </script>
</div>
